/**
 * Created by Administrator on 2017/4/6 0006.
 */
var Music=[];
WeiXinAudioController={
    Create:function(getArr){
        var controller={};
        var audioLength=getArr.length;
        var bl_wx=false;

        document.addEventListener("WeixinJSBridgeReady", whetherWeiXinOpen, false);

        function whetherWeiXinOpen(){
            bl_wx=true;
            bala();
        }

        if(!bl_wx){
            bala();
        }

        function bala(){
            for(var z=0;z<getArr.length;z++) {
                var src=getArr[z].split('|')[0];
                var name=getArr[z].split('|')[1];

                var audio = document.createElement('audio');
                audio.id = "Audio"+z;
                audio.src = src;
                audio.class = "media-audio";

                Music[name]=audio;
                document.body.appendChild(audio);
                console.log(document.getElementById("Audio1"));
                audio.play();

                audio.addEventListener("canplay", aa);
            }
        }

        function aa(e){
            audioLength--;
            getTrue();
            e.target.pause();
            e.target.removeEventListener("canplay",aa);
        }

        function getTrue(){
            if(audioLength==0) {
                document.dispatchEvent(new CustomEvent("audioLoaded", {detail: 1}));
            }
        }

        controller.skip=function(){
            document.dispatchEvent(new CustomEvent("audioLoaded", {detail: 1}));
        }


        return controller;
    }
}
AudioSkip={
    skip:function(){
        document.dispatchEvent(new CustomEvent("audioLoaded", {detail: 1}));
    }
}
